package com.tuanchauict.android.englishtip.timer;

import java.util.TimerTask;

import com.tuanchauict.android.englishtip.R;
import com.tuanchauict.android.englishtip.widget.Widget;

import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.util.Log;
import android.widget.RemoteViews;

public class UpdateTask extends TimerTask{

	private RemoteViews remoteViews;
	private AppWidgetManager appWidgetManager;
	private ComponentName thisWidget;
	private String[] str = {"ABC", "DEF", "GHI"};
	private int count = 0;
	
	public UpdateTask(Context context, AppWidgetManager appWidgetManager) {
		// TODO Auto-generated constructor stub
		this.appWidgetManager = appWidgetManager;
		remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
		thisWidget = new ComponentName(context, Widget.class);
		//read database list word
	}
	
	@Override
	public void run() {
		updateTextView(count);
		appWidgetManager.updateAppWidget(thisWidget, remoteViews);
		count = (count++)%str.length;
		
		
	}
	
	private void updateTextView(int index){
		remoteViews.setTextViewText(R.id.widget_view_word, str[index]);
		remoteViews.setTextViewText(R.id.widget_view_mean, "mean of " + str[index]);
	}
	
	
}
